import 'dart:core';

import 'package:flutter/cupertino.dart';
import 'package:flutter_application_cyber/model/cn_strategy_model.dart';
import 'package:flutter_application_cyber/net/cn_net_helper.dart';
// import 'package:provider/provider.dart';

import '../model/cn_net_response.dart';
// import '../pool/object_cache.dart';

class CnStrategyViewModel extends ChangeNotifier {
  CnStrategyModel? _strategy;
  static CnStrategyViewModel? _info;

  CnStrategyModel? get strategy => _strategy;

  void setStrategy(strategy) {
    _strategy = strategy;
    notifyListeners();
  }

  CnStrategyViewModel._();

  factory CnStrategyViewModel.getInfo() {
    return _info ??= CnStrategyViewModel._();
  }


/*
* 策略请求
* */
  void questStrategy() {
    CnNetHelper.strategyGet((value) {
      HDHResponseData? responseData = value;
      //print("审核模式(返回结果)${value}");
      if (responseData!=null&&responseData.code == 0 && responseData.data != null) {
        CnStrategyModel strategyViewModel =
            CnStrategyModel.coverFromJson(value.data);
        setStrategy(strategyViewModel);
      }
    });
  }

/*
* 策略请求(异步)
* */
  Future<void> questStrategyBlock() async {
    HDHResponseData? responseData = await CnNetHelper.strategyGetBlock();
    if (responseData!=null&&responseData.code == 0 && responseData.data != null) {
      CnStrategyModel model = CnStrategyModel.coverFromJson(responseData.data);
      setStrategy(model);
      //print("审核模式(返回结果)${model.isReviewPkg}");
    }
  }
}
